import React, { useEffect, useRef, useState } from 'react';
import { connect, history } from 'umi';
import { Alert, Button, Space, Tag, Modal, notification, Row, Col, Checkbox, Form } from 'antd'
import TableDataBlock from '@/components/TableDataBlock';
import PopImgShow from '@/components/PopImgShow';
import SearchCondition from '@/components/SearchCondition';
import { cashWith_status ,promoter_commission_typeInfo} from '@/common/contact'
import { uploadFile } from '@/utils/utils';
import Indentation from '@/components/Indentation';
const PromoterList = (props) => {
    const { loading, dispatch, list, zm } = props;
    const { location } = history
    const { query } = location
    const { accessId ,id} = query
    const childRef = useRef();
    const [form] = Form.useForm();
    let time = null
    const [visible, setVisible] = useState(false);
    const [codeVisible, setCodeVisible] = useState(false)
    const [selectList, setSelectList] = useState(false)
    const [shopId, setShopId] = useState([])
    const [params, setSearchParams] = useState({
      
    })
    const [shopVisible, setShopVisible] = useState(false)
    const [selectedRow, setSelectedRow] = useState({
        selectedRowKeys: [],
        type: 'checked',
        preserveSelectedRowKeys: true,
        onChange: (val, selectedRows) => {
            setSelectedRow({
                ...selectedRow,
                selectedRowKeys: val,
                rowKeyList: selectedRows
            });
        },

    });
    const fetchUrl = () => {
        dispatch({
            type: 'promoter/fetchActivityUrl',
            callback: (e) => {
                const { activityUrl } = e
                setCodeVisible({
                    show: true,
                    detail: {
                        url: activityUrl
                    }
                })
            }
        })
    }
    const fakeExportPromoter = () => {
        dispatch({
            type: 'promoter/fakeExportCommissionPromoter',
            payload: {
                ...params
            },
            callback: (e) => {
                const { url } = e
                uploadFile(url)
            }
        })

    }

    useEffect(() => { handleCallback() }, [params])

    // 搜索参数
    const searchItems = [
        {
            label: '推广员',
            name: 'promoterKeyword',
        },
        {
            label: '提现时间',
            type: 'rangePicker',
            name: 'createStartTime',
            end: 'createEndTime',
        },
        {
            label: '状态',
            name: 'status',
            type: 'select',
            select: cashWith_status,

        },
    ];
    const getColumns = [
        {
            title: '推广员名称',
            dataIndex: 'promoterName',
        },
        {
            title: '状态',
            dataIndex: 'status',
            render: (e) => {
                return cashWith_status[e]
            }
        },
        {
            title: '审核时间',
            dataIndex: 'checkTime',
        },
        {
            title: '审核备注',
            dataIndex: 'checkRemark',
        },
       
        {
            title: '申请佣金',
            dataIndex: 'applyCommission',
        },
        {
            title: '实际佣金',
            dataIndex: 'realCommission',
        },
        {
            title: '佣金类型',

            dataIndex: 'commissionType',
            render: (e) => {
                return promoter_commission_typeInfo[e]
            }
        },
        {
            title: '打款时间',

            dataIndex: 'payedTime',
        },
        {
            title: '提现时间',

            dataIndex: 'createTime',
        },
        {
            title: '审核人',

            dataIndex: 'checkAdminName',
        },
        {
            title: '打款员工',
            dataIndex: 'payedAdminName',
        },
        {
            title: '银行卡号',
            dataIndex: 'bankCard',

        },
        {
            title: '银行名称',
            dataIndex: 'bankName',

        },
        {
            title: '银行户名',
            dataIndex: 'bankAccount',

        },
    ];
    const handleCallback = () => {
        childRef.current.fetchGetData();
    };
    const handleSaveRole = (detail = {}) => {
        setVisible({
            show: true,
            detail,
        });
    };
    return (
        <div>
            <Row gutter={[36, 12]}>

                <Col span={24}>
                </Col>
                <Col span={24}>
                    <div style={{ background: '#f5f5f5', padding: 24 }}>
                        <SearchCondition
                            form={form}
                            handleSearch={(e) => {
                                setSearchParams(e);
                            }}
                            searchItems={searchItems}
                        ></SearchCondition>
                    </div>
                </Col>
                
                <Col span={24}>
                    <TableDataBlock
                        // rowSelection={selectedRow}
                        cRef={childRef}
                        loading={loading}
                        params={{ ...params, promoterId:id }}
                        firstFetch={false}
                        columns={getColumns}
                        rowKey={(record) => `${record.id}`}
                        dispatchType="promoter/fetchPromoterWithdraw"
                        {...list}
                    ></TableDataBlock>
                </Col>
            </Row>
        </div >
    );
};

export default connect(({ promoter, loading }) => ({
    list: promoter.promoterWithdrawList,
    loading: loading.effects['promoter/fetchPromoterWithdraw']
}))(PromoterList);
